/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bluetoothserver.dataStore;

import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author Philip
 */
public class QuestionCollection {
    ArrayList <Question>questions;
    Iterator <Question>i;
    public static final int MULTICHOICE = 0;
    public static final int NUMERIC = 1;
    public static final int YES_NO = 2;
    public static final int TRUE_FALSE = 3;
    public static final int SEQUENCE = 4;
    public static final int MULTIMARK = 5;
    public static final int VOTING = 6;
    public static final int RATING = 7;
    public static final int TEXT_ENTRY = 8;
    
    public QuestionCollection(int size){
        questions = new ArrayList(size);
        this.createIt();
    }
    
    public QuestionCollection(){
        questions = new ArrayList();
        this.createIt();
    }
    
    private void createIt(){
        i = questions.iterator();
    }
    
    public void addQuestion(Question q){
        questions.add(q);
    }
    
    public void remove(Question q){
        Iterator<Question> search = questions.iterator();
        boolean found = false;
        while(search.hasNext()||!found){
            Question s = search.next();
            if(s.getQuestion().compareTo(q.getQuestion())==0){
                found = true;
                search.remove();
            }
        }
    }
    
    public void remove(int i){
        questions.remove(i);
    }
    
    public Question getQuestion(String q){
        Iterator<Question> search = questions.iterator();
        Question returnable = null;
        boolean found = false;
        while(search.hasNext()||!found){
            Question s = search.next();
            if(s.getQuestion().compareTo(q)==0){
                found = true;
                returnable = s;
            }
        }
        return returnable;
    }
    
    public void replaceQuestion(int i, Question replacement){
        questions.add(i, replacement); 
        questions.remove(i+1);
    }
    
    public void addQuestion(Question q, int pos){
        questions.add(pos, q);
    }
    
    public boolean hasNext(){
        return i.hasNext();
    }
    
    public ArrayList<Question> getList(){
        return questions;
    }
    
    public void importArrray(ArrayList<Question> q){
        questions = q;
    }
    
}
